package open.witype.filetiper.fragment.menu;

import android.app.Activity;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import open.witype.filetiper.R;
import open.witype.filetiper.activity.home.HomeActivity;
import open.witype.filetiper.fragment.menu.adapter.MenuRecyclerAdapter;
import open.witype.filetiper.custom.DragRecyclerView;
import open.witype.filetiper.fragment.menu.db.FavoDBAdapter;
import open.witype.filetiper.fragment.BaseFragment;

/**
 * Created by Typer on 2015/6/1 0001.
 */
public class MenuFragment extends BaseFragment {

    private DragRecyclerView recyclerView;

    private HomeActivity activity;

    private MenuRecyclerAdapter adapter;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        root = inflater.inflate(R.layout.fragment_menu,null);
        initMenu();
        return root;
    }

    public void initMenu(){
        recyclerView = (DragRecyclerView)root.findViewById(R.id.menu_recycler);
        FavoDBAdapter dbAdapter = FavoDBAdapter.getInstance(activity);
        dbAdapter.open();
        adapter = new MenuRecyclerAdapter(dbAdapter.getFavoList());
        dbAdapter.close();
        adapter.setItemClickListener(activity.itemClickListener);
        recyclerView.setAdapter(adapter);
    }

    @Override
    public void onAttach(Activity activity) {
        super.onAttach(activity);
        this.activity = (HomeActivity)activity;
    }
}
